Package excel.autofit

Source Code of excel.autofit.ApacheAutoFit

package excel.autofit;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class ApacheAutoFit
{
  public static void main(String[] args) throws Exception
  {
    InputStream inStream = new FileInputStream("data/workbook.xls");
    Workbook workbook = WorkbookFactory.create(inStream);
   
    Sheet sheet = workbook.createSheet("new sheet");
    sheet.autoSizeColumn(0); //adjust width of the first column
    sheet.autoSizeColumn(1); //adjust width of the second column
   
    FileOutputStream fileOut;
    fileOut = new FileOutputStream("data/AutoFit_Apache.xls");
    workbook.write(fileOut);
    fileOut.close();
  }
}
TOP

Related Classes of excel.autofit.ApacheAutoFit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.